<template>
	<view>
		<view class="input-box">
			<input type="password" v-model="password" placeholder="请输入密码" class="ipt" placeholder-class="hold" />
		</view>
		<u-button class="u-submit" :custom-style="{width:'630rpx',marginTop:'60rpx'}" :loading="loginLoading"
			@click="submit" type="primary">确认修改</u-button>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				password: "",
				loginLoading: false
			}
		},
		methods: {
			submit() {
				if (!this.password) {
					this.$u.func.showToast({
						title: '请输入新密码',
					})
					return false
				}
				this.loginLoading = true
				this.$u.api.user.updatePassword({
					newPassword: this.password,
					parentId: this.userInfo.user_id
				}).then(data => {
					this.loginLoading = false
					if (data.code === 200 && data.success) {
						this.$refs.uToast.show({
							title: `修改成功`,
							type: 'success',
							duration: 1000
						})
						setTimeout(() => {
							this.$u.func.logout()
						}, 1000)
					}
				}).catch(err => {
					this.loginLoading = false
				})
			}
		}
	}
</script>

<style lang="scss">
	.input-box {
		margin: 60rpx;
		padding: 30rpx;
		border: 2rpx solid #f6f6f6;
		display: flex;
		align-items: center;
		font-size: 28rpx;
		width: 630rpx;

		.ipt {
			flex: 1;
		}
	}
</style>
